﻿using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Text;

namespace TestLargeModel.Services
{
    public class AIService
    {
        private readonly HttpClient _httpClient;

        public AIService(HttpClient httpClient)
        {
            _httpClient = httpClient;
            _httpClient.BaseAddress = new Uri("https://ark.cn-beijing.volces.com"); // 替换为豆包AI的API地址
        }

        public async Task<string> CallDoubaiAIAsync(object data)
        {
            var json = JsonConvert.SerializeObject(data);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "1a57ee11-6361-4aae-a62f-8e819850e8dc"); // 替换为你的API密钥

            var response = await _httpClient.PostAsync("/api/v3/chat/completions", content); // 替换为具体的API端点

            response.EnsureSuccessStatusCode(); // 确保响应状态为200

            var result = await response.Content.ReadAsStringAsync();
            return result; // 或根据需要解析和返回数据
        }
    }
}
